package practice;

import java.util.*;

/**
 * 万能单词拼写
 */
public class UniversalWordSpell {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = Integer.parseInt(sc.nextLine());
            List<String> list = new ArrayList<>(n);
            for (int i = 0; i < n ; i++) {
                list.add(sc.nextLine());
            }
            String matchStr = sc.nextLine();
            long result = list.stream()
                    .filter(s -> canSpellWord(s, matchStr))
                    .count();
            System.out.println(result);
        }
    }

    private static boolean canSpellWord(String word,String matchStr) {
        Map<Character, Integer> hashMap = new HashMap<>(matchStr.length());
        // 匹配串加入哈希表
        for (int i = 0; i < matchStr.length(); i++) {
            char c = matchStr.charAt(i);
            hashMap.put(c, hashMap.getOrDefault(c,0)+1);
        }

        for (int i = 0; i < word.length(); i++) {
            char c = word.charAt(i);
            Integer count = hashMap.get(c);
            if (count != null) {
                if (count > 1) {
                    hashMap.put(c,count-1);
                } else {
                    hashMap.remove(c);
                }
            } else {
                // 没有这个字符 就去找万能字符
                Integer markCount = hashMap.get('?');
                if (markCount == null) {
                    return false;
                } else {
                    if (markCount > 1) {
                        hashMap.put('?',markCount-1);
                    } else {
                        hashMap.remove('?');
                    }
                }
            }
        }
        return true;
    }
}
